<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>在线五子棋对战游戏</title>
		<script src="https://cdn.bootcss.com/jquery/3.4.0/jquery.min.js"></script>
	</head>
	<style type="text/css">
		#pan{
			border: 2px solid firebrick;
			margin-top: 30px;
		}
	</style>
	<body>
		<div id="pan">
		</div>
		<script type="text/javascript">
			var pan = new Array();
			var _html = ""
			for(var i = 0; i < 30; i++){
				var temp = new Array()
				_html += '<table border="1" id="pan_table"><tr>'
				for(var j = 0; j < 30; j++){
					var num = GetRandomNum(-1, 1)
					temp.push(num)
					num = num == 0 ? "" : num
					_html += "<td id=s"+i+"-"+j+">"+num+"</td>"
				}
				pan.push(temp)
// 				document.write(temp);
// 				document.write("<br />");
				temp = []
				_html += '</tr></table>'
			}
			console.log(pan)
			$("#pan_table").html(_html)
			
			
			function GetRandomNum(Min, Max) {
				return (Min + Math.round((Math.random()) * (Max - Min)))
			}
			
			 var b = function (tArray) {
				console.log(tArray)
				for (var i = 0; i < tArray.length-4; i++) {
					for (var j = 0; j < tArray.length-4; j++) {
						if(tArray[i][j] == tArray[i][j+1] && tArray[i][j] == tArray[i][j+2] && tArray[i][j] == tArray[i][j+3] && tArray[i][j] == tArray[i][j+4] && tArray[i][j] == 1){
							console.log(i, j, tArray[i][j])
							console.log(i, j+1, tArray[i][j+1])
							console.log(i, j+2, tArray[i][j+2])
							console.log(i, j+3, tArray[i][j+3])
							console.log(i, j+4, tArray[i][j+4])
							$("#s"+i+"-"+j).css({'background':'forestgreen'})
							$("#s"+i+"-"+(j+1)).css({'background':'forestgreen'})
							$("#s"+i+"-"+(j+2)).css({'background':'forestgreen'})
							$("#s"+i+"-"+(j+3)).css({'background':'forestgreen'})
							$("#s"+i+"-"+(j+4)).css({'background':'forestgreen'})
							// alert('黑色1胜利');
							return '黑色胜利';
						}
						if(tArray[i][j] == tArray[i+1][j] && tArray[i][j] == tArray[i+2][j] && tArray[i][j] == tArray[i+3][j]  && tArray[i][j] ==tArray[i+4][j] && tArray[i][j] == -1){
							console.log(i, j, tArray[i][j])
							console.log(i+1, j, tArray[i+1][j])
							console.log(i+2, j, tArray[i+2][j])
							console.log(i+3, j, tArray[i+3][j])
							console.log(i+4, j, tArray[i+4][j])
							$("#s"+i+"-"+j).css({'background':'forestgreen'})
							$("#s"+(i+1)+"-"+j).css({'background':'forestgreen'})
							$("#s"+(i+2)+"-"+j).css({'background':'forestgreen'})
							$("#s"+(i+3)+"-"+j).css({'background':'forestgreen'})
							$("#s"+(i+4)+"-"+j).css({'background':'forestgreen'})
							// alert('白色1胜利')
							return '白色胜利';
						}
						if(tArray[i][j] == tArray[i+1][j+1] && tArray[i][j] == tArray[i+2][j+2] && tArray[i][j] == tArray[i+3][j+3] && tArray[i][j] == tArray[i+4][j+4] && tArray[i][j] == 1){
							console.log(i, j, tArray[i][j])
							console.log(i+1, j+1, tArray[i+1][j+1])
							console.log(i+2, j+2, tArray[i+2][j+2])
							console.log(i+3, j+3, tArray[i+3][j+3])
							console.log(i+4, j+4, tArray[i+4][j+4])
							$("#s"+i+"-"+j).css({'background':'forestgreen'})
							$("#s"+(i+1)+"-"+(j+1)).css({'background':'forestgreen'})
							$("#s"+(i+2)+"-"+(j+2)).css({'background':'forestgreen'})
							$("#s"+(i+3)+"-"+(j+3)).css({'background':'forestgreen'})
							$("#s"+(i+4)+"-"+(j+4)).css({'background':'forestgreen'})
							// alert('黑色2胜利');
							return '黑色胜利';
						}
						if(tArray[i][j] == tArray[i+1][j+1] && tArray[i][j] == tArray[i+2][j+2] && tArray[i][j] == tArray[i+3][j+3] && tArray[i][j] == tArray[i+4][j+4] && tArray[i][j] == -1){
							console.log(i, j, tArray[i][j])
							console.log(i+1, j+1, tArray[i+1][j+1])
							console.log(i+2, j+2, tArray[i+2][j+2])
							console.log(i+3, j+3, tArray[i+3][j+3])
							console.log(i+4, j+4, tArray[i+4][j+4])
							$("#s"+i+"-"+j).css({'background':'forestgreen'})
							$("#s"+(i+1)+"-"+(j+1)).css({'background':'forestgreen'})
							$("#s"+(i+2)+"-"+(j+2)).css({'background':'forestgreen'})
							$("#s"+(i+3)+"-"+(j+3)).css({'background':'forestgreen'})
							$("#s"+(i+4)+"-"+(j+4)).css({'background':'forestgreen'})
							// alert('白色2胜利')
							return '白色胜利';
						}
					}
				}
				alert('平手')
			}
			console.log(b(pan))

		</script>
	</body>
</html>
